package DP;

import java.util.Scanner;

public class 背包问题01 {
    class Solution {
        public int backpack(int[] weight, int[] value, int bag) {

            int n = weight.length;
            int[][] dp = new int[n][bag + 1];

            // 找准遍历顺序，去初始化
            for (int j = weight[0]; j <= bag; j++) {
                dp[0][j] = value[0];
            }
            for (int i = 1; i < n; i++) {  // 物品
                for (int j = 1; j <= bag; j++) {  // 背包
                    if (j < weight[i]) {
                        dp[i][j] = dp[i - 1][j];
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight[i ]] + value[i]);
                    }
                }
            }
            return dp[n-1][bag];
        }
    }

    public static void main(String[] args) {

        Solution solution = new 背包问题01().new Solution();
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int bag = scanner.nextInt();
        int[] weight = new int[n];
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            value[i] = scanner.nextInt();
        }

        int res = solution.backpack(weight, value, bag);
        System.out.println(res);
    }
}
